
#include "logger.hpp"

Logger::Logger() { }

Logger::~Logger()
{
	this->log.close();
}

int Logger::open(std::string &file_log)
{
	this->log.open(file_log.c_str());
	this->mode = DEFAULT_MESSAGE_MODE;

	if (this->log)
		return 1;
	else
		return 0;
}

int Logger::open(std::string &file_log, int mode)
{
	this->log.open(file_log.c_str());
	this->mode = mode;

	if (this->log)
		return 1;
	else
		return 0;
}

int Logger::open(const char* file_log)
{
	this->log.open(file_log);
	this->mode = DEFAULT_MESSAGE_MODE;

	if (this->log)
			return 1;
		else
			return 0;
}

int Logger::open(const char* file_log, int mode)
{
	this->log.open(file_log);
	this->mode = mode;

	if (this->log)
			return 1;
		else
			return 0;
}

void Logger::setInformationMode(int mode)
{
	this->mode = mode;
}

void Logger::reportErrorMessage(std::string reporter_class, std::string reporter_method, std::string detail)
{
	this->log << "[ Error ] " << reporter_class << " - " << reporter_method << ": "<< detail <<std::endl;
}

void Logger::reportErrorMessage(std::string reporter_class, std::string reporter_method, std::string detail, int line)
{
	this->log << "[ Error ] " << reporter_class << " - " << reporter_method << ": "<< detail
			  << ", en linea " << line <<std::endl;
}

void Logger::reportErrorMessage(std::string reporter_class, std::string reporter_method, std::string detail, int line, int field)
{
	this->log << "[ Error ] " << reporter_class << " - " << reporter_method << ": "<< detail
			  << ", en linea " << line << ", campo "<< field <<std::endl;
}

void Logger::reportWarningMessage(std::string reporter_class, std::string reporter_method, std::string detail)
{
	if(this->mode >= 2)
		this->log << "[Warning] " << reporter_class << " - " << reporter_method << ": "<< detail <<std::endl;
}

void Logger::reportWarningMessage(std::string reporter_class, std::string reporter_method, std::string detail, int line)
{
	if(this->mode >= 2)
		this->log << "[Warning] " << reporter_class << " - " << reporter_method << ": "<< detail
				  << ", en linea " << line <<std::endl;
}

void Logger::reportWarningMessage(std::string reporter_class, std::string reporter_method, std::string detail, int line, int field)
{
	if(this->mode >= 2)
		this->log << "[Warning] " << reporter_class << " - " << reporter_method << ": "<< detail
				  << ", en linea " << line << ", campo "<< field <<std::endl;
}

void Logger::reportSuccessMessage(std::string reporter_class, std::string reporter_method, std::string detail)
{
	if(this->mode >= 3)
		this->log << "[Success] " << reporter_class << " - " << reporter_method << ": "<< detail <<std::endl;
}

void Logger::reportSuccessMessage(std::string reporter_class, std::string reporter_method, std::string detail, int line)
{
	if(this->mode >= 3)
		this->log << "[Success] " << reporter_class << " - " << reporter_method << ": "<< detail
				  << ", en linea " << line <<std::endl;
}

void Logger::reportSuccessMessage(std::string reporter_class, std::string reporter_method, std::string detail, int line, int field)
{
	if(this->mode >= 3)
		this->log << "[Success] " << reporter_class << " - " << reporter_method << ": "<< detail
				  << ", en linea " << line << ", campo "<< field <<std::endl;
}
